package com.personnel_management.controller;

import com.personnel_management.pojo.Depart;
import com.personnel_management.pojo.Staff;
import com.personnel_management.service.DepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("depart")
public class DepartController {
    @Autowired
    private DepartService departService;
    @CrossOrigin("*")
    @RequestMapping("add")
    @ResponseBody
    //添加部门
    public Integer addDepart(Depart depart) {
        return departService.addDepart(depart);
    }

    @CrossOrigin("*")
    @RequestMapping("delete")
    @ResponseBody
    //删除部门(根据id)
    public Integer deleteDepart(Integer id) {
        return departService.deleteDepart(id);
    }

    @CrossOrigin("*")
    @RequestMapping("set")
    @ResponseBody
    //修改部门(城市、部门名称)
    public Integer setDepart(Depart depart) {
        return departService.setDepart(depart);
    }

    @CrossOrigin("*")
    @RequestMapping("find")
    @ResponseBody
    //查询部门(按照id)
    public Depart seleteOne(int id) {
        return departService.seleteOne(id);
    }

    @CrossOrigin("*")
    @RequestMapping("findAll")
    @ResponseBody
    //查询部门(所有)
    public List<Depart> selectDeparts(Depart depart) {
        return departService.selectDeparts(depart);
    }

    @CrossOrigin("*")
    @RequestMapping("findByid")
    @ResponseBody
    //查询该部门的员工(根据id)
    public List<Staff> selectStaffs(int id) {
        return departService.selectStaffs(id);
    }
}
